package com.kotlin.mvpdemo.ui.login;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.kotlin.mvpdemo.R;
import com.kotlin.mvpdemo.base.BaseActivity;
import com.kotlin.mvpdemo.databinding.ActivityLoginBinding;
import com.kotlin.mvpdemo.entity.ApiResponse;
import com.kotlin.mvpdemo.ui.main.MainActivity;

/**
 * author : fang.zhang
 * e-mail : initzf@126.com
 * date   : 2020/6/6
 * desc   : 登录业务
 */
public class LoginActivity extends BaseActivity<LoginView, LoginPressenter, ActivityLoginBinding> implements LoginView, View.OnClickListener {

    @Override
    protected LoginPressenter getPresenter() {
        return new LoginPressenter();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_login;
    }

    @Override
    protected ActivityLoginBinding getViewBind() {
        return ActivityLoginBinding.inflate(getLayoutInflater());
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mViewBinding.login.setOnClickListener(this);
    }

    @Override
    public void loginSuccess() {
        startActivity(new Intent(this, MainActivity.class));
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.login:
                mPresenter.login(mViewBinding.username.getText().toString(), mViewBinding.password.getText().toString());
                break;
        }
    }
}
